#include "game_state_pool.h"
#include <iostream>

namespace NES
{
	GameStatePool::GameStatePool(int capacity) : m_pool(capacity)
	{
		for (int i = 0; i < capacity; i++)
		{
			m_pool.push_back(new GameState());
		}
	}
	GameState * GameStatePool::get(Emulator * emu)
	{
		GameState * gs = NULL;
		if (m_pool.empty()) 
		{
			gs =  new GameState();
		}
		else
		{
			gs = m_pool.back();
			m_pool.pop_back();
		}
		if (emu != NULL) {
			emu->save_state(gs);
		}
		return gs;
	}
}